cmake_minimum_required(VERSION 3.10)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

if(NOT CMAKE_CONFIGURATION_TYPES)
    if(NOT CMAKE_BUILD_TYPE)
        set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
    endif()
    string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_TYPE_LOWER)
    set(MOC_DIR "${CMAKE_CURRENT_BINARY_DIR}/${BUILD_TYPE_LOWER}/moc")
    set(RCC_DIR "${CMAKE_CURRENT_BINARY_DIR}/${BUILD_TYPE_LOWER}/rcc")
    set(UI_DIR "${CMAKE_CURRENT_BINARY_DIR}/${BUILD_TYPE_LOWER}/forms")
    set(OBJECTS_DIR "${CMAKE_CURRENT_BINARY_DIR}/${BUILD_TYPE_LOWER}/obj")
    set(CMAKE_OBJECT_PATH_PREFIX ${OBJECTS_DIR})
else()
    set(LOWER_CONFIG "$<LOWER_CASE:$<CONFIG>>")
    set(MOC_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LOWER_CONFIG}/moc")
    set(RCC_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LOWER_CONFIG}/rcc")
    set(UI_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LOWER_CONFIG}/forms")
    set(OBJECTS_DIR "${CMAKE_CURRENT_BINARY_DIR}/${LOWER_CONFIG}/obj")
    set(CMAKE_OBJECT_PATH_PREFIX ${OBJECTS_DIR})
endif()

if(UNIX)
    if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
        set(BIN_BASE "../bin_x86_64_linux")
    elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64")
        set(BIN_BASE "../bin_arm64_linux")
    else()
        set(BIN_BASE "../bin_linux")
    endif()
elseif(WIN32)
    set(BIN_BASE "../bin_x86_win32")
endif()

# 输出目录
if(NOT CMAKE_CONFIGURATION_TYPES)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BIN_BASE}/${BUILD_TYPE_LOWER}")
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BIN_BASE}/${BUILD_TYPE_LOWER}")
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BIN_BASE}/${BUILD_TYPE_LOWER}")
    set(PROJECT_LIBDIR "${BIN_BASE}/${BUILD_TYPE_LOWER}")
else()
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BIN_BASE}/${LOWER_CONFIG}")
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BIN_BASE}/${LOWER_CONFIG}")
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${BIN_BASE}/${LOWER_CONFIG}")
    set(PROJECT_LIBDIR "${BIN_BASE}/${LOWER_CONFIG}")
endif()

